﻿using MexicanControl.model;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using static MexicanControl.model.Save;

namespace MexicanControl
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void exit_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (e.ChangedButton == MouseButton.Left && e.ClickCount == 2)
                {
                    MessageBoxResult result = MessageBox.Show("Exit orders will not be made,Do you really want to quit?", "Exit", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
                    if (result == MessageBoxResult.Yes)
                    {
                        foreach (System.Diagnostics.Process thisProc in System.Diagnostics.Process.GetProcesses())
                        {
                            if (thisProc.ProcessName == "BlueportCoffee")
                            {
                                if (!thisProc.CloseMainWindow())
                                    thisProc.Kill(); //当发送关闭窗口命令无效时强行结束进程     
                            }
                            //if (thisProc.ProcessName == "MINIGKP")
                            //{
                            //    if (!thisProc.CloseMainWindow())
                            //        thisProc.Kill(); //当发送关闭窗口命令无效时强行结束进程     
                            //}
                        }
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            System.Windows.Application.Current.Shutdown();
                        }));
                    }
                }
            }
            catch (Exception)
            {
                return;
            }

        }
        /// <summary>
        ///   状态  0 关状态  1 开状态 2 已开机 3 上电 4 下电 5 已使能 6 下使能 7 已运行 8 继续运行 9 已报警 10 已暂停  11已停止 ,12 机械臂状态查询
        /// </summary>
        /// <param name="robotName"></param>
        /// <param name="type"> </param>
        public void Robot_CZ(string robotName, int type)
        {
            try
            {
                if (CoffeeSocket != null)
                {
                    ClientList clientList = new ClientList();
                    MessageClientList coffeelist = MessageClientList.Instance;
                    coffeelist.Name = robotName;
                    coffeelist.type = type;
                    clientList.message = coffeelist;
                    clientList.code = 3;
                    CoffeeSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(clientList)));
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        /// <summary>
        ///   状态  0 关状态  1 开状态 2 已开机 3 上电 4 下电 5 已使能 6 下使能 7 已运行 8 继续运行 9 已报警 10 已暂停  11已停止 ,12 机械臂状态查询
        /// </summary>
        /// <param name="robotName"></param>
        /// <param name="type"> </param>
        public void Robot_CZ_N(string robotName, int type)
        {
            try
            {
                if (IceSocket != null)
                {
                    ClientList clientList = new ClientList();
                    MessageClientList coffeelist = MessageClientList.Instance;
                    coffeelist.Name = robotName;
                    coffeelist.type = type;
                    clientList.message = coffeelist;
                    clientList.code = 3;
                    IceSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(clientList)));
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        /// <summary>
        ///   状态  0 关状态  1 开状态 2 已开机 3 上电 4 下电 5 已使能 6 下使能 7 已运行 8 继续运行 9 已报警 10 已暂停  11已停止 ,12 机械臂状态查询
        /// </summary>
        /// <param name="robotName"></param>
        /// <param name="type"> </param>
        public void Robot_CZ_Ns(string robotName, int type)
        {
            try
            {
                if (IceSocket != null)
                {
                    ClientList clientList = new ClientList();
                    MessageClientList coffeelist = MessageClientList.Instance;
                    coffeelist.Name = robotName;
                    coffeelist.type = type;
                    clientList.message = coffeelist;
                    clientList.code = 3;
                    IceSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(clientList)));
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        /// <summary>
        /// 上电
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void L_SD_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (L_SD.Tag.ToString() == "1")
                {
                    Robot_CZ("Reload_L", 2);
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        /// <summary>
        /// 报警
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void L_BJ_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (L_BJ.Tag.ToString() == "1")
                {
                    Robot_CZ("Reload_L", 9);
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        /// <summary>
        /// 本体上电
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void L_BTSD_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (L_BTSD.Tag.ToString() == "1")
                {
                    Robot_CZ("Reload_L", 3);
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        /// <summary>
        /// 本体下电
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void L_BTXD_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (L_BTXD.Tag.ToString() == "1")
                {
                    Robot_CZ("Reload_L", 4);
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        /// <summary>
        /// 上使能
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void L_SSN_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (L_SSN.Tag.ToString() == "1")
                {
                    Robot_CZ("Reload_L", 5);
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        /// <summary>
        /// 下使能
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void L_XSN_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (L_XSN.Tag.ToString() == "1")
                {
                    Robot_CZ("Reload_L", 6);
                }
            }
            catch (Exception)
            {
                return;
            }
        }
/// <summary>
/// 运行程序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>

        private void L_YXCX_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (L_YXCX.Tag.ToString() == "1")
                {
                    Robot_CZ("Reload_L", 7);
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        /// <summary>
        /// 停止运行
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void L_TZCX_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (L_TZCX.Tag.ToString() == "1")
                {
                    Robot_CZ("Reload_L", 11);
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        /// <summary>
        /// 暂停程序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void L_ZTCX_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (L_ZTCX.Tag.ToString() == "1")
                {
                    Robot_CZ("Reload_L", 10);
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        /// <summary>
        /// 继续程序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void L_JXCX_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (L_JXCX.Tag.ToString() == "1")
                {
                    Robot_CZ("Reload_L", 8);
                }
            }
            catch (Exception)
            {
                return;
            }
        }

        private void Reload_L_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                Robot_CZ("Reload_L", 12);
            }
            catch (Exception)
            {
                return;
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                wuliao.Visibility = Visibility.Visible;
                CoffeeQuYu.Visibility = Visibility.Collapsed;
            }
            catch (Exception)
            {
                return;
            }
        }

        private void CoffeeRobot_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                wuliao.Visibility = Visibility.Collapsed;
                CoffeeQuYu.Visibility = Visibility.Visible;
            }
            catch (Exception)
            {
                return;
            }
        }
        public void Send(string name, string tag)
        {
            try
            {
                if (CoffeeSocket != null)
                {
                    if (isJZ)
                    {
                        ClientList clientList = new ClientList();
                        MessageClientList coffeelist = MessageClientList.Instance;
                        coffeelist.Name = name;
                        coffeelist.type = double.TryParse(tag, out double do1) ? do1 : 0;
                        clientList.message = coffeelist;
                        clientList.code = 0;
                        CoffeeSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(clientList)));
                    }
                    else
                    {
                        MessageBox.Show("Please update later, the program is loading!");
                    }
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        public static Socket serverSocket;
        public static Socket CoffeeSocket;
        public static Socket IceSocket;
        public static Socket DPSocket;
        private static byte[] result = new byte[4096];
        private static int myProt = 8885;  //端口 
        public static bool ismake = false;
        public static bool isJZ = false;
        public List<ClientList> clientLists = new List<ClientList>();
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                //saveDeviceMatter save = new saveDeviceMatter();
                //save.matterStatusJson = JsonConvert.SerializeObject(CoffeeMatters.Instance);
                //save.deviceStatusJson = JsonConvert.SerializeObject(deviceStatus.Instance);
                //var saves = JsonConvert.SerializeObject(save);
                //HttpMsg.Instance.saveDeviceMatterMsg(saves);
                //ICECC_CMB.SelectedIndex = 0;
                //GSCC_CMB.SelectedIndex = 0;
                //GJCC_CMB.SelectedIndex = 0;
                //PCJCC_CMB.SelectedIndex = 0;
                CoffeeMake();
            }
            catch (Exception)
            {
                return;
            }
        }
        #region 服务器链接
        /// <summary>
        /// 服务器启动监听各种信息动态
        /// </summary>
        public void CoffeeMake()
        {
            try
            {
                string LocalIP = "192.168.45.77";
                var host = Dns.GetHostEntry(Dns.GetHostName());
                foreach (var ips in host.AddressList)
                {
                    if (ips.AddressFamily == AddressFamily.InterNetwork)
                    {
                        LocalIP = ips.ToString();
                        // Console.WriteLine"IP Address = " + (ips.ToString());
                    }
                }
                //服务器IP地址 
                IPAddress ip = IPAddress.Parse(LocalIP);
                serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                serverSocket.Bind(new IPEndPoint(ip, myProt)); //绑定IP地址：端口 
                serverSocket.Listen(10);  //设定最多10个排队连接请求 
                Console.WriteLine("启动监听{0}成功", serverSocket.LocalEndPoint.ToString());
                //通过Clientsoket发送数据 
                Thread myThread = new Thread(ListenClientConnect);
                myThread.IsBackground = true;
                myThread.Start();
                //foreach (System.Diagnostics.Process thisProc in System.Diagnostics.Process.GetProcesses())
                //{
                //    if (thisProc.ProcessName == "BlueportCoffee")
                //    {
                //        if (!thisProc.CloseMainWindow())
                //            thisProc.Kill(); //当发送关闭窗口命令无效时强行结束进程     
                //    }
                //    if (thisProc.ProcessName == "MINIGKP")
                //    {
                //        if (!thisProc.CloseMainWindow())
                //            thisProc.Kill(); //当发送关闭窗口命令无效时强行结束进程     
                //    }
                //}
                //Process ps = new Process();
                //string yourURL = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"coffee";
                //ps.StartInfo.FileName = "BlueportCoffee.exe";
                //ps.StartInfo.WorkingDirectory = yourURL;
                //ps.Start();
                //Thread.Sleep(1000);
                //Process ps1 = new Process();
                //string yourURL1 = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"显示屏";
                //ps1.StartInfo.FileName = "MINIGKP.exe";
                //ps1.StartInfo.WorkingDirectory = yourURL1;
                //ps1.Start();
            }
            catch (Exception ex)
            {
                serverSocket.Shutdown(SocketShutdown.Both);
                serverSocket.Close();
                CoffeeMake();
                return;
            }
        }
        /// <summary> 
        /// 监听客户端连接 
        /// </summary> 
        private void ListenClientConnect()
        {
            try
            {
                while (true)
                {
                    Socket clientSocket = serverSocket.Accept();
                    string ip = ((IPEndPoint)clientSocket.RemoteEndPoint).Address.ToString();
                    Console.WriteLine("点单");
                    Thread receiveThread = new Thread(ReceiveMessage);
                    receiveThread.IsBackground = true;
                    receiveThread.Start(clientSocket);
                    Thread.Sleep(10);
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        /// <summary> 
        /// 接收消息 
        /// </summary> 
        /// <param name="clientSocket"></param> 
        private void ReceiveMessage(object clientSockets)
        {
            Socket myClientSocket = (Socket)clientSockets;

            while (true)
            {
                try
                {
                    //通过clientSocket接收数据 
                    int receiveNumber = myClientSocket.Receive(result);
                    if (receiveNumber == 0) continue;
                    try
                    {
                        var msg = Encoding.UTF8.GetString(result, 0, receiveNumber);
                        if (msg.Trim().Length != 0)
                        {
                            var making = JsonConvert.DeserializeObject<ClientList>(msg);
                            if (making != null)
                            {
                                if (making.code == 4)
                                {
                                    CoffeeSocket = myClientSocket;
                                }
                                else if (making.code == 11)
                                {
                                    DPSocket = myClientSocket;
                                    if (DPSocket != null)
                                    {
                                        Thread.Sleep(1000);
                                        ClientList clientList = new ClientList();
                                        MessageClientList coffeelist = MessageClientList.Instance;
                                        clientList.message = coffeelist;
                                        clientList.IsMake = ismake;
                                        DPSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(clientList)));
                                    }
                                }
                                else
                                {
                                    clientLists.Add(making);
                                }
                            }
                        }
                        Thread.Sleep(10);
                    }
                    catch (Exception)
                    {
                    }
                }
                catch (Exception ex)
                {
                    break;
                }
            }

        }
        public void MsgShowServer()
        {

            try
            {
                while (true)
                {
                    try
                    {
                        if (clientLists.Count > 0)
                        {
                            var ClientList = clientLists[0];
                            if (ClientList != null)
                            {
                                if (ClientList.code == 2)
                                {
                                    CoffeeMsg(ClientList.MsgBol);
                                }
                                else if (ClientList.code == 3)
                                {
                                    if (ClientList.message.Name == "Reload_L")
                                    {
                                        RobotSel_L(ClientList.robotMsg);
                                    }
                                }
                                else if (ClientList.code == 0)
                                {
                                    DOSelect(ClientList.message.Name, ClientList.message.type);
                                }
                                else if (ClientList.code == 10)
                                {
                                    if (DPSocket != null)
                                    {
                                        Thread.Sleep(1000);
                                        ClientList clientList = new ClientList();
                                        MessageClientList coffeelist = MessageClientList.Instance;
                                        clientList.message = coffeelist;
                                        clientList.IsMake = ClientList.IsMake;
                                        DPSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(clientList)));
                                        ismake = ClientList.IsMake;
                                    }
                                }
                                else if (ClientList.code == 12)
                                {
                                    isJZ = true;
                                }
                            }
                            clientLists.RemoveAt(0);
                        }
                    }
                    catch (Exception)
                    {
                    }
                    Thread.Sleep(100);
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        public void CoffeeMsg(WuLiaoCoffeeSel wuLiaoCoffee)
        {
            try
            {
                this.Dispatcher.BeginInvoke(new Action(delegate
                {
                    CCK1_B.Background = wuLiaoCoffee.OutMealCup_Sel_Bol1 ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    CCK1_F.Foreground = wuLiaoCoffee.OutMealCup_Sel_Bol1 ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    CCK2_B.Background = wuLiaoCoffee.OutMealCup_Sel_Bol2 ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    CCK2_F.Foreground = wuLiaoCoffee.OutMealCup_Sel_Bol2 ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    CCK3_B.Background = wuLiaoCoffee.OutMealCup_Sel_Bol3 ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    CCK3_F.Foreground = wuLiaoCoffee.OutMealCup_Sel_Bol3 ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    CCK4_B.Background = wuLiaoCoffee.OutMealCup_Sel_Bol4 ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    CCK4_F.Foreground = wuLiaoCoffee.OutMealCup_Sel_Bol4 ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    FKJYB_B.Background = wuLiaoCoffee.SealingMachine_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    FKJYB_F.Foreground = wuLiaoCoffee.SealingMachine_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    TBJYB_B.Background = wuLiaoCoffee.LabelingMachine_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    TBJYB_F.Foreground = wuLiaoCoffee.LabelingMachine_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    KFBFK_B.Background = wuLiaoCoffee.LBQFK1_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    KFBFK_F.Foreground = wuLiaoCoffee.LBQFK1_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    NCBFK_B.Background = wuLiaoCoffee.LBQFK2_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    NCBFK_F.Foreground = wuLiaoCoffee.LBQFK2_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    KFBJC_B.Background = wuLiaoCoffee.CupCapacity_Sel_Bol1 ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    KFBJC_F.Foreground = wuLiaoCoffee.CupCapacity_Sel_Bol1 ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    NCBJC_B.Background = wuLiaoCoffee.CupCapacity_Sel_Bol2 ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    NCBJC_F.Foreground = wuLiaoCoffee.CupCapacity_Sel_Bol2 ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    JBCGJC1_B.Background = wuLiaoCoffee.TakeCup_Sel_Bol1 ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    JBCGJC1_F.Foreground = wuLiaoCoffee.TakeCup_Sel_Bol1 ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    JBCGJC2_B.Background = wuLiaoCoffee.TakeCup_Sel_Bol2 ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    JBCGJC2_F.Foreground = wuLiaoCoffee.TakeCup_Sel_Bol2 ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    GJC_B.Background = wuLiaoCoffee.LidCapacity_Sel_Bol1 ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    GJC_F.Foreground = wuLiaoCoffee.LidCapacity_Sel_Bol1 ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    NN1_B.Background = wuLiaoCoffee.Milk_Sel_Bol1 ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    NN1_F.Foreground = wuLiaoCoffee.Milk_Sel_Bol1 ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    NNYBJ1_B.Background = wuLiaoCoffee.EarlyWarningMilk_Sel_Bol1 ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    NNYBJ1_F.Foreground = wuLiaoCoffee.EarlyWarningMilk_Sel_Bol1 ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    LGFK_B.Background = wuLiaoCoffee.LGQFK1_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    LGFK_F.Foreground = wuLiaoCoffee.LGQFK1_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    NN2_B.Background = wuLiaoCoffee.Milk_Sel_Bol2 ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    NN2_F.Foreground = wuLiaoCoffee.Milk_Sel_Bol2 ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    NNYBJ2_B.Background = wuLiaoCoffee.EarlyWarningMilk_Sel_Bol2 ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    NNYBJ2_F.Foreground = wuLiaoCoffee.EarlyWarningMilk_Sel_Bol2 ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    YGS_B.Background = wuLiaoCoffee.CapPressingUP_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    YGS_F.Foreground = wuLiaoCoffee.CapPressingUP_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    YGZ_B.Background = wuLiaoCoffee.CapPressingMin_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    YGZ_F.Foreground = wuLiaoCoffee.CapPressingMin_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    YGX_B.Background = wuLiaoCoffee.CapPressingDown_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    YGX_F.Foreground = wuLiaoCoffee.CapPressingDown_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    FSTJC_B.Background = wuLiaoCoffee.WastewaterBucket_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    FSTJC_F.Foreground = wuLiaoCoffee.WastewaterBucket_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    CFJJC_B.Background = wuLiaoCoffee.CoffeeWarn ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    CFJJC_F.Foreground = wuLiaoCoffee.CoffeeWarn ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    JQRJC_B.Background = wuLiaoCoffee.RobotWarn ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    JQRJC_F.Foreground = wuLiaoCoffee.RobotWarn ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    ZBJJC_B.Background = wuLiaoCoffee.Ice1_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    ZBJJC_F.Foreground = wuLiaoCoffee.Ice1_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    KFCZ_B.Background = wuLiaoCoffee.CoffeeWeight_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    KFCZ_F.Foreground = wuLiaoCoffee.CoffeeWeight_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    BQLCZ_B.Background = wuLiaoCoffee.MilkWeight_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    BQLCZ_F.Foreground = wuLiaoCoffee.MilkWeight_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                }));
                //TestDelegateInvoke testDelegate = new TestDelegateInvoke(DelegateInvokeMethod);
                //testDelegate.BeginInvoke(null, null);
            }
            catch (Exception)
            {
                return;
            }
        }
        /// <summary>
        /// 单个按钮改变状态
        /// </summary>
        /// <param name="name"></param>
        /// <param name="tag"></param>
        public void DOSelect(string name, double tag)
        {
            try
            {
                switch (name)
                {
                    case "KFBLB_IMG":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            KFBLB_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            KFBLB_IMG.Tag = tag;
                            KFBLB_IMG.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                        }));
                        break;
                    case "NCBLB_IMG":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            NCBLB_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            NCBLB_IMG.Tag = tag;
                            NCBLB_IMG.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                        }));
                        break;
                    case "LG_IMG":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            LG_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            LG_IMG.Tag = tag;
                            LG_IMG.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                        }));
                        break;
                    case "YGS_IMG":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            YGS_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            YGS_IMG.Tag = tag;
                            YGS_IMG.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                        }));
                        break;
                    case "YGZ_IMG":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            YGZ_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            YGZ_IMG.Tag = tag;
                            YGZ_IMG.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                        }));
                        break;
                    case "YGX_IMG":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            YGX_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            YGX_IMG.Tag = tag;
                            YGX_IMG.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                        }));
                        break;
                    case "DHJDJZD_IMG":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            DHJDJZD_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            DHJDJZD_IMG.Tag = tag;
                            DHJDJZD_IMG.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                        }));
                        break;
                    case "KSJCS_IMG":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            KSJCS_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            KSJCS_IMG.Tag = tag;
                            KSJCS_IMG.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                        }));
                        break;
                    case "KFJYCDD_IMG":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            KFJYCDD_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            KFJYCDD_IMG.Tag = tag;
                            KFJYCDD_IMG.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                        }));
                        break;
                    case "JQRYCDD_IMG":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            JQRYCDD_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            JQRYCDD_IMG.Tag = tag;
                            JQRYCDD_IMG.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                        }));
                        break;
                    case "ZBJYCDD_IMG":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            ZBJYCDD_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            ZBJYCDD_IMG.Tag = tag;
                            ZBJYCDD_IMG.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                        }));
                        break;
                    case "NCJYCDD_IMG":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            NCJYCDD_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            NCJYCDD_IMG.Tag = tag;
                            NCJYCDD_IMG.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                        }));
                        break;
                    case "TBJYCDD_IMG":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            TBJYCDD_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            TBJYCDD_IMG.Tag = tag;
                            TBJYCDD_IMG.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                        }));
                        break;
                    case "BYBJDD_IMG":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            BYBJDD_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            BYBJDD_IMG.Tag = tag;
                            BYBJDD_IMG.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                        }));
                        break;
                    default:
                        break;
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        /// <summary>
        /// 给按钮变颜色
        /// </summary>
        /// <param name="btn">要变颜色得按钮</param>
        /// <param name="type">1，正常 2，接通变1 3，不缺料 4，缺料</param>
        /// <param name="img">要变颜色得按钮 开</param>
        ///  <param name="img1">要变颜色得按钮 关</param>
        public void BtnShow(Button btn, int type, Image img, Image img1)
        {
            try
            {
                this.Dispatcher.BeginInvoke(new Action(delegate
                {
                    if (type == 0)//正常状态do
                    {
                        btn.Tag = 0;
                        img.Source = new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                        img1.Source = new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png"));

                    }
                    else if (type == 1)//接通变1do
                    {
                        btn.Tag = 1;
                        img1.Source = new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                        img.Source = new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png"));
                    }
                }));
            }
            catch (Exception)
            {
                return;
            }
        }

        public void RobotSel_L(RobotMsg robotMsg)
        {
            try
            {
                this.Dispatcher.BeginInvoke(new Action(delegate
                {
                    robot_kj_L.Source = robotMsg.Robot_YKJ_L ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    robot_sd_L.Source = robotMsg.Robot_SD_L ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    robot_sn_L.Source = robotMsg.Robot_SN_L ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    robot_yx_L.Source = robotMsg.Robot_YX_L ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    robot_zt_L.Source = robotMsg.Robot_ZT_L ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    robot_bj_L.Source = robotMsg.Robot_BJ_L ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    robot_tz_L.Source = robotMsg.Robot_TZ_L ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png")); ;
                    RobotYN_L(robotMsg);
                }));
            }
            catch (Exception)
            {
                return;
            }
        }
        public void RobotYN_L(RobotMsg robotMsg)
        {
            try
            {
                LTypeKJ_L.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LTypeBJ_L.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LOpenBTDY_L.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LCloseBTDY_L.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LOpenSSN_L.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LCloseSSN_L.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LOpenYXCX_L.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LCloseTZCX_L.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LContinueZTCX_L.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LCloseJXCX_L.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                L_SD.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                L_BJ.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                L_BTSD.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                L_BTXD.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                L_SSN.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                L_XSN.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                L_YXCX.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                L_ZTCX.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                L_TZCX.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                L_JXCX.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                L_SD.Tag = "0";
                L_BJ.Tag = "0";
                L_BTSD.Tag = "0";
                L_BTXD.Tag = "0";
                L_SSN.Tag = "0";
                L_XSN.Tag = "0";
                L_YXCX.Tag = "0";
                L_ZTCX.Tag = "0";
                L_TZCX.Tag = "0";
                L_JXCX.Tag = "0";
                if (!robotMsg.Robot_YKJ_L && !robotMsg.Robot_BJ_L && !robotMsg.Robot_YX_L && !robotMsg.Robot_SN_L && !robotMsg.Robot_ZT_L && !robotMsg.Robot_SD_L && !robotMsg.Robot_TZ_L)
                {
                    LTypeKJ_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    L_SD.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_SD.Tag = "1";
                }
                else if (robotMsg.Robot_YKJ_L)
                {
                    LOpenBTDY_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    L_BTSD.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_BTSD.Tag = "1";
                }
                else if (robotMsg.Robot_SD_L)
                {
                    LCloseBTDY_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    LOpenSSN_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    L_BTXD.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_SSN.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_BTXD.Tag = "1";
                    L_SSN.Tag = "1";
                }
                else if (robotMsg.Robot_SN_L)
                {
                    LOpenYXCX_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    LCloseSSN_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    L_YXCX.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_XSN.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_XSN.Tag = "1";
                    L_YXCX.Tag = "1";
                }
                else if (robotMsg.Robot_YX_L)
                {
                    LCloseTZCX_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    LContinueZTCX_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    L_TZCX.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_ZTCX.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_ZTCX.Tag = "1";
                    L_TZCX.Tag = "1";
                }
                else if (robotMsg.Robot_TZ_L)
                {
                    LOpenYXCX_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    LCloseSSN_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    L_YXCX.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_XSN.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_XSN.Tag = "1";
                    L_YXCX.Tag = "1";
                }
                else if (robotMsg.Robot_ZT_L)
                {
                    LCloseTZCX_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    LCloseJXCX_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    L_JXCX.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_TZCX.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_JXCX.Tag = "1";
                    L_TZCX.Tag = "1";
                }
                else if (robotMsg.Robot_BJ_L)
                {
                    LTypeBJ_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    L_BJ.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_BJ.Tag = "1";
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        #endregion

        private void IMG_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                var name = (sender as Image).Name;
                var tag = (sender as Image).Tag;
                Send(name, tag.ToString());
            }
            catch (Exception)
            {
                return;
            }
        }
    }
}
